home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / X-Ray / X-Ray INIT Source / utils.c < prev    next >
Encoding:
Text File  |  1999-06-06  |  3.6 KB  |  134 lines  |  [TEXT/CWIE]

  1. // Copyright (C) 1999 Eric Roccasecca.  All rights reserved.
  2.  
  3. #include "X_Ray_Priv.h"
  4.  
  5.  
  6. void DebugNum (long bugNum)
  7. {
  8.     Str15    bugStr;
  9.     
  10.     NumToString (bugNum, bugStr);
  11.     DebugStr (bugStr);
  12. }
  13.  
  14. //    This function is not copyrighted by Eric Roccasecca.
  15. //    It very well might be copyrighted someone else.
  16. //    Whoever you are, thanks for a handy function.
  17. void NumToHexString (long number, StringPtr string)
  18. {
  19.     char    clookup[16] = "0123456789ABCDEF";
  20.     
  21.     string[0]  = 8;
  22.     string[1]  = clookup[(number & 0xf0000000)>>28];
  23.     string[2]  = clookup[(number & 0x0f000000)>>24];
  24.     string[3]  = clookup[(number & 0x00f00000)>>20];
  25.     string[4]  = clookup[(number & 0x000f0000)>>16];
  26.     string[5]  = clookup[(number & 0x0000f000)>>12];
  27.     string[6]  = clookup[(number & 0x00000f00)>>8];
  28.     string[7]  = clookup[(number & 0x000000f0)>>4];
  29.     string[8]  = clookup[(number & 0x0000000f)];
  30. }
  31.  
  32.  
  33. //    This function is not copyrighted by Eric Roccasecca
  34. //    It very well might be copyrighted someone else.
  35. //    Whoever you are, thanks for a handy function.
  36. Boolean isPressed (unsigned short key)
  37. {
  38.     unsigned char keyMap[16];
  39.  
  40.     GetKeys( (unsigned long *) keyMap);
  41.     return ( ( keyMap[key>>3] >> (key & 7) ) & 1);
  42. }
  43.  
  44.  
  45. // takes a rect and sets it's upper left corner to zero, while maintaing
  46. // the horizontal and vertical dommensions
  47. void X_Ray_NormalizeRect (Rect *theRect)
  48. {
  49.     theRect->right = theRect->right - theRect->left;
  50.     theRect->bottom = theRect->bottom - theRect->top;
  51.     theRect->top = 0;
  52.     theRect->left = 0;
  53. }
  54.  
  55. // converts a rect from local to global coordinates
  56. void X_Ray_LocalToGlobalRect (Rect *theRect)
  57. {
  58.     Point    localPoint;
  59.     
  60.     localPoint.h = theRect->left;
  61.     localPoint.v = theRect->top;
  62.     LocalToGlobal (&localPoint);
  63.     OffsetRect (theRect, localPoint.h - theRect->left, localPoint.v - theRect->top);
  64. }
  65.  
  66. // converts a rect from global to local coordinates
  67. void X_Ray_GlobalToLocalRect (Rect *theRect)
  68. {
  69.     Point    globalPoint;
  70.     
  71.     globalPoint.h = theRect->left;
  72.     globalPoint.v = theRect->top;
  73.     GlobalToLocal (&globalPoint);
  74.     OffsetRect (theRect, globalPoint.h - theRect->left, globalPoint.v - theRect->top);
  75. }
  76.  
  77. // converts a polygon from local to global coordinates
  78. void X_Ray_LocalToGlobalPoly (PolyHandle thePoly)
  79. {
  80.     Point    localPoint;
  81.     
  82.     localPoint.h = (*thePoly)->polyBBox.left;
  83.     localPoint.v = (*thePoly)->polyBBox.top;
  84.     LocalToGlobal (&localPoint);
  85.     OffsetPoly (thePoly, localPoint.h - (*thePoly)->polyBBox.left, localPoint.v - (*thePoly)->polyBBox.top);
  86. }
  87.  
  88. // converts a polygon from global to local coordinates
  89. void X_Ray_GlobalToLocalPoly (PolyHandle thePoly)
  90. {
  91.     Point    globalPoint;
  92.     
  93.     globalPoint.h = (*thePoly)->polyBBox.left;
  94.     globalPoint.v = (*thePoly)->polyBBox.top;
  95.     GlobalToLocal (&globalPoint);
  96.     OffsetPoly (thePoly, globalPoint.h - (*thePoly)->polyBBox.left, globalPoint.v - (*thePoly)->polyBBox.top);
  97. }
  98.  
  99. // converts a region from local to global coordinates
  100. void X_Ray_LocalToGlobalRgn (RgnHandle theRgn)
  101. {
  102.     Point    localPoint;
  103.     
  104.     localPoint.h = (*theRgn)->rgnBBox.left;
  105.     localPoint.v = (*theRgn)->rgnBBox.top;
  106.     LocalToGlobal (&localPoint);
  107.     OffsetRgn (theRgn, localPoint.h - (*theRgn)->rgnBBox.left, localPoint.v - (*theRgn)->rgnBBox.top);
  108. }
  109.  
  110. // converts a region from global to local coordinates
  111. void X_Ray_GlobalToLocalRgn (RgnHandle theRgn)
  112. {
  113.     Point    globalPoint;
  114.     
  115.     globalPoint.h = (*theRgn)->rgnBBox.left;
  116.     globalPoint.v = (*theRgn)->rgnBBox.top;
  117.     GlobalToLocal (&globalPoint);
  118.     OffsetRgn (theRgn, globalPoint.h - (*theRgn)->rgnBBox.left, globalPoint.v - (*theRgn)->rgnBBox.top);
  119. }
  120.  
  121.  
  122. extern    short        X_RayDrawLevel;
  123.  
  124. // a region verification utility function
  125. // useful for seeing what exactly is the shape of theRgn
  126. void ConfirmRgn (RgnHandle theRgn)
  127. {
  128.     X_RayDrawLevel++;
  129.     InvertRgn (theRgn);
  130.     Debugger();
  131.     InvertRgn (theRgn);
  132.     X_RayDrawLevel--;
  133. }
  134.